﻿/************************************************************************************
* Copyright (c) 2019 All Rights Reserved.
*命名空间：Merge.BLL
*文件名： Parameter
*创建人： Liebeskind
*创建时间：2019/6/24 17:25:10
*描述
*=====================================================================
*修改标记
*修改时间：2019/6/24 17:25:10
*修改人：Liebeskind
*描述：
************************************************************************************/
using Commonality.DAL.MySQL;
using Commonality.Model.Tray;
using Commonality.Model.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Merge.BLL
{
    public class Parameter
    {
        public static string parameterFeilName = Application.StartupPath + @"\Parameter\Parameter.xml";
        #region 数据库
        public static void MySQLParameterLoad()
        {
            try
            {
                MySqlFunction.InitMySQLFunction();
                MySQLParameter.Host = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "MySQL", "Host");
                MySQLParameter.Password = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "MySQL", "Password");
                MySQLParameter.UserID = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "MySQL", "UserID");
                MySqlFunction.MySql.DataSource = MySQLParameter.Host;
                MySqlFunction.MySql.Password = MySQLParameter.Password;
                MySqlFunction.MySql.UserId = MySQLParameter.UserID;
            }
            catch (Exception)
            {
            }
        }
        public static void UpdateMySQLHost(string host)
        {
            XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "MySQL", "Host", host);
            MySqlFunction.MySql.DataSource = host;
        }
        public static void UpdateMySQLPassword(string password)
        {
            XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "MySQL", "Password", password);
            MySqlFunction.MySql.Password = password;
        }
        public static void UpdateMySQLUserId(string userId)
        {
            XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "MySQL", "UserID", userId);
            MySqlFunction.MySql.UserId = userId;
        }
        #endregion
        #region Model类型集合元素
        public static void TrayModelElementLoad()
        {
            try
            {
                string[] modelX01 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X01").Split(new char[] { '|' });
                string[] modelX03 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X03").Split(new char[] { '|' });
                string[] modelX05 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X05").Split(new char[] { '|' });
                string[] modelX08 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X08").Split(new char[] { '|' });
                string[] modelX13 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X13").Split(new char[] { '|' });
                string[] modelX15 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X15").Split(new char[] { '|' });
                foreach (var item in modelX01)
                {
                    if (item != "" && item != null) Tray.X01.Add(item);
                }
                foreach (var item in modelX03)
                {
                    if (item != "" && item != null) Tray.X03.Add(item);
                }
                foreach (var item in modelX05)
                {
                    if (item != "" && item != null) Tray.X05.Add(item);
                }
                foreach (var item in modelX08)
                {
                    if (item != "" && item != null) Tray.X08.Add(item);
                }
                foreach (var item in modelX13)
                {
                    if (item != "" && item != null) Tray.X13.Add(item);
                }
                foreach (var item in modelX15)
                {
                    if (item != "" && item != null) Tray.X15.Add(item);
                }
            }
            catch (Exception)
            {
            }
        }
        public static void UpdateTrayModelElement(TrayModel model, List<string> modelSets)
        {
            string Sets = "";
            foreach (var item in modelSets)
            {
                Sets += item + "|";
            }
            switch (model)
            {
                case TrayModel.NULL:
                    break;
                case TrayModel.X01:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X01", Sets);
                    break;
                case TrayModel.X03:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X03", Sets);
                    break;
                case TrayModel.X05:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X05", Sets);
                    break;
                case TrayModel.X08:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X08", Sets);
                    break;
                case TrayModel.X13:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X13", Sets);
                    break;
                case TrayModel.X15:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X15", Sets);
                    break;
                default:
                    break;
            }
        }
        #endregion
    }
}
